/**
 *
 */
package com.sihai.ehr.web.action.ajax;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.Duty;
import com.sihai.ehr.model.biz.WorkNo;
import com.sihai.ehr.model.sys.Organization;
import com.sihai.ehr.service.DutyService;
import com.sihai.ehr.service.WorkNoService;
import com.sihai.ehr.web.action.EHRAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import java.util.List;

/**
 * @author wxn
 * @since 2012-6-19 21:12
 */
public class WorkNoAction extends EHRAction {

    private static final long serialVersionUID = 2121333028480225454L;

    @BeanInject
    private WorkNoService workNoService;
    
    private boolean result;

    private WorkNo workNo;

    @Action(value = "/workno/save", results = {
            @Result(name = "success", type = "json", params = {"root", "result"})
    })
    public String save() {
        if(workNo != null || organizationId == null){
            if(workNo.getId() != null){//edit
                WorkNo w = workNoService.get(workNo.getId());
                w.setActivity(workNo.getActivity());
                workNoService.save(w);
            }else{//save
                Organization o = new Organization();
                o.setId(organizationId);
                workNo.setOrganization(o);
                workNoService.save(workNo);
            }
            result = true;
        }else{
            result = false;
        }
        
        return SUCCESS;
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public WorkNo getWorkNo() {
        return workNo;
    }

    public void setWorkNo(WorkNo workNo) {
        this.workNo = workNo;
    }
}
